﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace Infrastructure
{
    /// <summary>
    /// 加密安全类
    /// </summary>
    public static class Encryption
    {
        /// <summary>
        /// 获取密码的加密值
        /// 密码MD5后反转再MD5
        /// </summary>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public static string GetPasswordMd5(string password)
        {
            Func<string, string> md5Func = (pwd) =>
            {
                var data = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(pwd)).Select(item => item.ToString("x").PadLeft(2, '0'));
                return string.Join(string.Empty, data);
            };
            var md5 = md5Func(password.NullThenEmpty()).Reverse();
            return md5Func(new string(md5.ToArray()));
        }
    }
}
